// ==================================================================
// 描 述：
// 作 者：王征:D
// 创建时间：2019/05/15 16:54:06
// ==============================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using Yunchang;

namespace AutoChess
{
    public class ACGroupBuffDetailPanel : MonoBehaviour
    {
        public GroupSpriteKit GroupSprite;
        public Text GroupName;
        public Text GroupDesc;
        public Text[] ChessNumTxt;
        public Text[] BuffTxt;
        public GroupSpriteKit[] HeadSprites;
        public GameObject[] DescBg;

        public void SetData(int acHeroGroup, int heroNum)
        {
            AutoChessManager.Ins.SetSameBuffEffect(true, acHeroGroup);

            gameObject.SetActive(true);
            var allBuffs = Table.Blo.AutoChessBlo.GetGroupBuffsByGroupId(acHeroGroup);
            var acGroup = Table.Blo.AutoChessBlo.GetGroup(acHeroGroup);
            var heroGroup = Table.Blo.TableHeroBlo.GetTableHeroGroup(acHeroGroup);
            GroupName.text = Table.Blo.AutoChessBlo.GetGroup(acHeroGroup).groupSkillName;
            GroupDesc.text = acGroup.desc;

            int textIndex = -1;
            int lastHeroNum = 0;
            for (int i = 0; i < allBuffs.Count; i++)
            {
                var buff = allBuffs[i];
                if (buff.needHeroNum == lastHeroNum)
                {
                    BuffTxt[textIndex].text += " " + buff.desc;
                }
                else
                {
                    ++textIndex;
                    lastHeroNum = buff.needHeroNum;

                    ChessNumTxt[textIndex].transform.parent.gameObject.SetActive(true);

                    BuffTxt[textIndex].text = buff.desc;
                    ChessNumTxt[textIndex].text = "x" + buff.needHeroNum.ToString();
                    if(heroNum >= buff.needHeroNum)
                    {
                        HeadSprites[textIndex].SetSpriteName("zizouqi_icon_ren5");
                        ChessNumTxt[textIndex].color = new Color(0.729f, 0.341f, 0.078f);
                        if (DescBg.Length > textIndex)
                            DescBg[textIndex].SetActive(false);
                    }
                    else
                    {
                        HeadSprites[textIndex].SetSpriteName("zizouqi_icon_ren6");
                        ChessNumTxt[textIndex].color = new Color(0.35f, 0.36f, 0.36f);
                        if (DescBg.Length > textIndex)
                            DescBg[textIndex].SetActive(true);
                    }
                }
            }

            ++textIndex;
            for (; textIndex < ChessNumTxt.Length; textIndex++)
            {
                ChessNumTxt[textIndex].transform.parent.gameObject.SetActive(false);
            }

            GroupSprite.SetSpriteName(acGroup.altasName);

            foreach (var item in BuffTxt)
            {
                var content = item.transform.parent.GetComponent<UI.AutoScrollContent>();
                if(content != null)
                    content.ResetToBeginning();
            }
        }

        public void Close()
        {
            AutoChessManager.Ins.SetSameBuffEffect(false);
            gameObject.SetActive(false);
        }
    }
}
